//
//  WbComposeToolBar.swift
//  Weibo
//
//  Created by HH on 16/12/10.
//  Copyright © 2016年 Weibo. All rights reserved.
//

import UIKit

enum composeToolBarType {
    //图片
    case picture
    //@
    case mention
    //话题
    case trend
    //表情
    case emoticon
    //加号
    case add
}

class WbComposeToolBar: UIStackView {
    
    var callBack:((Int)->())?

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    
    required init(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        axis = .horizontal
        distribution = .fillEqually
        
        let imageNameArray:[String] = ["compose_toolbar_picture",
                          "compose_mentionbutton_background",
                          "compose_trendbutton_background",
                          "compose_emoticonbutton_background",
                          "compose_add_background"]
        
        for (i,imageName) in imageNameArray.enumerated(){
            
            let btn = UIButton()
            
            btn.setImage(UIImage(named:imageName), for: .normal)
            btn.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
            btn.setBackgroundImage(#imageLiteral(resourceName: "compose_toolbar_background"), for: .normal)
            btn.tag = i
            //取消高亮显示效果
            btn.adjustsImageWhenHighlighted = false
            
            
            btn.addTarget(self, action: #selector(toolBarAction(sender:)), for: .touchUpInside)
            //写这个方法才能添加上子控件
            addArrangedSubview(btn)
            
            
        }
    }
    
    @objc private func toolBarAction(sender:UIButton){
        
        callBack?(sender.tag)
    }

}
